package com.atguigu.gmall.list.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.service.api.SearchService;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/list")
public class ListApiController {

    @Autowired
    private SearchService searchService;

    @GetMapping("/inner/import/sku/to/elastic/search/{skuId}")
    public Result<Void> importSkuToElasticSearch(@PathVariable("skuId") Long skuId) {
        searchService.importGoodsToElasticSearch(skuId);
        return Result.ok();
    }

    @GetMapping("/remove/goods/from/elastic/search/{skuId}")
    public Result<Void> removeGoodsFromElasticSearch(@PathVariable("skuId") Long skuId) {
        searchService.removeGoodsFromElasticSearch(skuId);
        return Result.ok();
    }

    @GetMapping("/inner/incr/goods/hot/score/{skuId}")
    public Result<Void> incrGoodsHotScore(@PathVariable("skuId") Long skuId) {

        searchService.incrHotScore(skuId);

        return Result.ok();
    }

    @PostMapping("/inner/do/search")
    public Result<SearchResponseVo> search(@RequestBody SearchParam searchParam) throws Throwable {
        return Result.ok(searchService.search(searchParam));
    }

}